package com.guage.controller;

import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.guage.commons.result.PageInfo;
import com.guage.model.ShopVideo;
import com.guage.service.IShopVideoService;
import com.guage.commons.base.BaseController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author dechao.yang
 * @since 2017-12-14
 */
@Controller
@RequestMapping("/shopVideo")
public class ShopVideoController extends BaseController {

    @Autowired private IShopVideoService shopVideoService;
    
    @GetMapping("/manager")
    public String manager() {
        return "admin/shop/shopVideo/shopVideoList";
    }
    
    
    @PostMapping("/dataGrid")
    @ResponseBody
    public Object dataGrid(Integer page, Integer rows, String sort, String order) {
        PageInfo pageInfo = new PageInfo(page, rows, sort, order);
        shopVideoService.selectDataGrid(pageInfo);
        return pageInfo;
    }
    
    /**
     * 添加页面
     * @return
     */
    @GetMapping("/addPage")
    public String addPage() {
        return "admin/shop/shopVideo/shopVideoAdd";
    }
    
    
     /**
     * 添加
     * @param 
     * @return
     */
    @PostMapping("/add")
    @ResponseBody
    public Object add(@Valid ShopVideo shopVideo) {
    	 shopVideoService.insert(shopVideo);
         return renderSuccess("添加成功！");
    }
    
    
    /**
     * 删除
     * @param id
     * @return
     */
    @PostMapping("/delete")
    @ResponseBody
    public Object delete(Long id) {
    	  shopVideoService.deleteById(id);
          return renderSuccess("删除成功！");
    }
    
    
     /**
     * 编辑页面
     * @param model
     * @param id
     * @return
     */
    @GetMapping("/editPage")
    public String editPage(Model model, Long id) {    	  	
        ShopVideo shopVideo = shopVideoService.selectById(id);
        model.addAttribute("shopVideo", shopVideo);
        return "admin/shop/shopVideo/shopVideoEdit";
    }
    
    /**
     * 更新
     * @param 
     * @return
     */
    @PostMapping("/edit")
    @ResponseBody
    public Object edit(@Valid ShopVideo shopVideo) {
    	shopVideoService.updateById(shopVideo);
        return renderSuccess("编辑成功！");
    }
}
